<?php
class LinkPager extends CLinkPager
{
	public $firstPageCssClass = 'first_undefinedstyle';
	public $lastPageCssClass = 'last_undefinedstyle';
	const CSS_SELECTED_PAGE = 'active';
	
	public $htmlOptions = array(
		'class' => ''
	);
	
	public $header = '';
	
	public function init()
	{
		parent::init();
		$this->firstPageLabel = '|&lt;&lt;';
		$this->lastPageLabel = '&gt;&gt;|';
		$this->prevPageLabel = t('page', 'Prev');
		$this->nextPageLabel = t('page', 'Next');
	}
	
	protected function createPageButton($label,$page,$class,$hidden,$selected)
	{
		if($hidden || $selected){
			if($hidden){
				return '';
			}
			if($selected){
				$class = ' ' . self::CSS_SELECTED_PAGE;
				return '<li class="'.$class.'">'.CHtml::link($label, '#').'</li>';
			}
		}
		return '<li class="'.$class.'">'.CHtml::link($label,$this->createPageUrl($page)).'</li>';
	}
	
	protected function createPageButtons()
	{
		if(($pageCount=$this->getPageCount())<=1)
			return array();

		list($beginPage,$endPage)=$this->getPageRange();
		$currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
		$buttons=array();

		// first page
		if(!$currentPage<=0){
			$buttons[]=$this->createPageButton($this->firstPageLabel,0,$this->firstPageCssClass,$currentPage<=0,false);
		}

		// prev page
		if(($page=$currentPage-1)<0)
			$page=0;
//		$buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);
		if(!$currentPage<=0){
			$buttons[]=$this->createPageButton($this->prevPageLabel,$page, '', $currentPage<=0,false);
		}

		// internal pages
		for($i=$beginPage;$i<=$endPage;++$i)
			$buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage);

		// next page
		if(($page=$currentPage+1)>=$pageCount-1)
			$page=$pageCount-1;
//		$buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);
		//if(!$currentPage>=$pageCount-1){
			$buttons[]=$this->createPageButton($this->nextPageLabel, $page, '', $currentPage>=$pageCount-1,false);
		//}

		// last page
		//if(!$currentPage>=$pageCount-1){
			$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,$this->lastPageCssClass,$currentPage>=$pageCount-1,false);
		//}

		return $buttons;
	}
}